package test.study.concurrent.thread._3_future.test;

import cn.hutool.core.thread.ThreadUtil;

import java.util.concurrent.TimeUnit;

public class Client {

    public Data request(String str) {
        //初始化
        FutureData future = new FutureData();
        //异步
        new Thread(() -> {
            //RealData的构建很慢，所以在单独的线程中进行
            RealData realData = new RealData("SADFASDF");
            ThreadUtil.sleep(3, TimeUnit.SECONDS);
            //setRealData()的时候会notify()等待在这个future上的对象
            future.setRealData(realData);
        }).start();
        //返回
        return future;
    }
}
